package cn.semyes.ylipfilter.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.semyes.ylipfilter.dao.custom.BaiduAccountDao;
import cn.semyes.ylipfilter.entity.BaiduAccountEntity;
import cn.semyes.ylipfilter.service.BaiduAccountService;

@Service
public class BaiduAccountServiceImpl implements BaiduAccountService {
	
	private BaiduAccountEntity baiduAccountEntity;
	
	@Autowired
	private BaiduAccountDao baiduAccountDao;

	@Override
	public void saveUser(int user_id, String user_name, String refresh_token, String create_time, String recent_time) {
		// TODO Auto-generated method stub
		baiduAccountEntity = new BaiduAccountEntity();
		
		baiduAccountEntity.setUser_id(user_id);
		baiduAccountEntity.setUser_name(user_name);
		baiduAccountEntity.setRefresh_token(refresh_token);
		baiduAccountEntity.setCreate_time(create_time);
		baiduAccountEntity.setRecent_time(recent_time);
		baiduAccountEntity.setCount_visit(1);
		baiduAccountDao.save(baiduAccountEntity);
	}

	@Override
	public int updateUser(int user_id, String recent_time) {
		// TODO Auto-generated method stub
		Map<String, Object> params = new HashMap<>();  
		params.put("user_id", user_id);
		params.put("recent_time", recent_time);
		return baiduAccountDao.update(params);
	}

	@Override
	public BaiduAccountEntity selectByUserId(int user_id) {
		// TODO Auto-generated method stub
		return baiduAccountDao.selectByUserId(user_id);
	}

}
